package com.stn.zjx.givingtreasure.activity.bi;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.came.viewbguilib.ButtonBgUi;
import com.stn.zjx.givingtreasure.R;
import com.stn.zjx.givingtreasure.base.BaseActivity;
import com.stn.zjx.givingtreasure.event.NetWorkEvent;
import com.stn.zjx.givingtreasure.fragment.importwallet.ImportKeystoreFragment;
import com.stn.zjx.givingtreasure.fragment.importwallet.ImportPrivatekeyFragment;
import com.stn.zjx.givingtreasure.fragment.importwallet.ImportMnemonicFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindArray;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ImportEthWalletActivity extends BaseActivity implements TabLayout.BaseOnTabSelectedListener {

    @BindView(R.id.back_bt)
    RelativeLayout backBt;
    @BindView(R.id.action_title)
    TextView actionTitle;
    @BindView(R.id.web_title)
    TextView webTitle;
    @BindView(R.id.action_add_bt)
    RelativeLayout actionAddBt;
    @BindView(R.id.action_refresh)
    RelativeLayout actionRefresh;
    @BindView(R.id.exit)
    RelativeLayout exit;
    @BindView(R.id.sure_bt)
    TextView sureBt;
    @BindView(R.id.share_bt)
    RelativeLayout shareBt;
    @BindView(R.id.more_bt)
    RelativeLayout moreBt;
    @BindView(R.id.release_bt)
    ButtonBgUi releaseBt;
    @BindView(R.id.tablayout)
    TabLayout tablayout;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    private ImportPrivatekeyFragment privatekey;
    private ImportKeystoreFragment keystore;
    private ImportMnemonicFragment zhuji;
    @BindArray(value = R.array.import_wallet)
    String[] strings;
    @Override
    public void networkStatus(NetWorkEvent netWorkEvent) {

    }

    @Override
    public void initComponent() {
        actionTitle.setText(getString(R.string.import_eth_wallet));
        List<Fragment> ar = new ArrayList<>();
        ar.add(zhuji=new ImportMnemonicFragment());
        ar.add(keystore=new ImportKeystoreFragment());
        ar.add(privatekey=new ImportPrivatekeyFragment());
        for (int i = 0; i < strings.length; i++) {
            TabLayout.Tab tabItem = tablayout.newTab();
            tabItem.setText(strings[i]);
            tablayout.addTab(tabItem);
        }
        tablayout.setTabGravity(TabLayout.GRAVITY_FILL);
        tablayout.addOnTabSelectedListener(this);
        viewpager.setAdapter(new TabAdapter(getSupportFragmentManager(), ar));
        tablayout.setupWithViewPager(viewpager);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_import_eth_wallet);
        ButterKnife.bind(this);
        initComponent();
    }

    @OnClick({R.id.back_bt})
    public void onViewClicked(View view) {
        Bundle bundle = new Bundle();
        switch (view.getId()) {
            case R.id.back_bt:
                finish();
                break;

        }
    }

    @Override
    public void onTabSelected(TabLayout.Tab tab) {

    }

    @Override
    public void onTabUnselected(TabLayout.Tab tab) {

    }

    @Override
    public void onTabReselected(TabLayout.Tab tab) {

    }

    public class TabAdapter extends FragmentPagerAdapter {

        private List<Fragment> fragments;


        public TabAdapter(FragmentManager fm, List<Fragment> fragments) {
            super(fm);
            this.fragments = fragments;
        }


        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        //设置tablayout标题
        @Override
        public CharSequence getPageTitle(int position) {
            return strings[position];

        }
    }
}
